package com.jingdianjichi.subject.handler;

import com.jingdianjichi.subject.common.enums.IsDeleteEnum;
import com.jingdianjichi.subject.common.enums.SubjectInfoTypeEnum;
import com.jingdianjichi.subject.convert.SubjectBriefConverter;
import com.jingdianjichi.subject.convert.SubjectJudgeConverter;
import com.jingdianjichi.subject.entity.SubjectInfoBO;
import com.jingdianjichi.subject.entity.SubjectOptionBO;
import com.jingdianjichi.subject.infra.basic.entity.SubjectBrief;
import com.jingdianjichi.subject.infra.basic.entity.SubjectJudge;
import com.jingdianjichi.subject.infra.basic.entity.SubjectMultiple;
import com.jingdianjichi.subject.infra.basic.service.impl.SubjectBriefServiceImpl;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.LinkedList;
import java.util.List;

/**
 * 简答题目的策略类
 */
@Component
public class BriefTypeHandler implements  SubjectTypeHandler{

    private final SubjectBriefServiceImpl subjectBriefService;

    public BriefTypeHandler(SubjectBriefServiceImpl subjectBriefService) {
        this.subjectBriefService = subjectBriefService;
    }

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        //判断题目的插入
        List<SubjectBrief> subjectBriefs=new LinkedList<>();
        //将选项BO转换为选项实体
        SubjectBrief subjectBrief = SubjectBriefConverter.Instatnce.convertBOToRadio(subjectInfoBO);
        //设置题目ID
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        //设置是否删除
        subjectBrief.setIsDeleted(IsDeleteEnum.UN_DELETED.getCode());
        //将选项实体添加到列表中
        subjectBriefs.add(subjectBrief);
        //插入单选题目的表
        subjectBriefService.batchInsert(subjectBriefs);
    }

    @Override
    public SubjectOptionBO query(Long id) {
        //获取简答题
        SubjectBrief subjectBrief = subjectBriefService.queryBySubjectId(id);
        //将获取的信息 封装到OptionBo中
        SubjectOptionBO subjectOptionBO=new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(subjectBrief.getSubjectAnswer());
        return subjectOptionBO;
    }
}
